package com.yan.aoptest;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author Administrator
 *         通过aop拦截后执行具体操作
 */
@Aspect
@Component
public class LogIntercept {

    @Pointcut("execution(public * com.yan.aoptest..*.*(..))")
    public void recordLog() {
    }

//    @Before("recordLog()")
//    public void before() {
//        this.printLog("已经记录下日志，在before之前执行");
//    }

    @Around("recordLog()")
    public void around(ProceedingJoinPoint pjp) throws Throwable {
        this.printLog("在Around之前执行");
        pjp.proceed();
        this.printLog("在Around之后执行");
    }

//    @After("recordLog()")
//    public void after() {
//        this.printLog("在after之后执行");
//    }

    private void printLog(String str) {
        System.out.println(str);
    }
}